package cn.tedu.oa.expenses.service.impl;

import cn.tedu.oa.expenses.mapper.ExpensesMapper;
import cn.tedu.oa.expenses.pojo.dto.ExpensesQuery;
import cn.tedu.oa.expenses.pojo.dto.ExpensesSaveParam;
import cn.tedu.oa.expenses.pojo.entity.Expenses;
import cn.tedu.oa.expenses.pojo.vo.ExpensesVO;
import cn.tedu.oa.expenses.service.ExpensesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class ExpensesServiceImpl implements ExpensesService {
    @Autowired
    ExpensesMapper expensesMapper;
    @Override
    public List<ExpensesVO> select(ExpensesQuery expensesQuery) {
        log.info("ExpensesServiceImpl.select()");
        List<ExpensesVO> list = expensesMapper.select(expensesQuery);
        return list;
    }

    @Override
    public void save(ExpensesSaveParam expensesSaveParam) {
        log.debug("ExpensesServiceImpl.save()"+expensesSaveParam);
        Expenses expenses = new Expenses();
        BeanUtils.copyProperties(expensesSaveParam,expenses);
        if (expenses.getId()==null){
            expenses.setCreateTime(new Date());
            expensesMapper.insert(expenses);
        }else {
            expenses.setUpdateTime(new Date());
            expensesMapper.update(expenses);
        }

    }

    @Override
    public void delete(Integer id) {
        log.debug("ExpensesServiceImpl"+id);
        expensesMapper.delete(id);

    }
}
